<template>
  <div>
    <Panel title="第三方充电数据统计">
      { directCount ,  idleAmountDc,  idleAmountAc,  deviceAmountAc,  zhiPercent, jiaoPercent, siteCount, liwang, guzhang, shiyonglv}
     <div slot="body">
       <div>直流总数(directCount): {{xingluochong.directCount}}</div>
       <div>空闲直流总数(idleAmountDc): {{xingluochong.idleAmountDc}}</div>
       <div>直流空闲比率(100%)：{{xingluochong.zhiPercent}}</div>
       <div>总交流(deviceAmountAc): {{xingluochong.deviceAmountAc}}</div>
       <div>空闲交流(idleAmountAc): {{xingluochong.idleAmountAc}}</div>
       <div>交流空闲比率(100%)：{{xingluochong.jiaoPercent}}</div>
       <div>统计站点数量： {{xingluochong.siteCount}}</div>
       <div>电价： {{xingluochong.elePrice}}</div>
       <div>会员电价： {{xingluochong.Member}}</div>
       <div>评分大于2的站点： {{xingluochong.memberCount}}</div>


       <div>快电</div>
       <div>直流总数: {{kuaidian.directCount}}</div>
       <div>空闲直流总数： {{kuaidian.idleAmountDc}}</div>
       
       <div>直流空闲比率 {{kuaidian.zhiPercent}}</div>
       <div>总交流 {{kuaidian.deviceAmountAc}}</div>
       <div>空闲交流 {{kuaidian.idleAmountAc}}</div>
       <div>交流空闲比率 {{kuaidian.jiaoPercent}}</div>
       <div>统计站点数量： {{kuaidian.siteCount}}</div>
       <div>离网： {{kuaidian.liwang}}</div>
       <div>故障： {{kuaidian.guzhang}}</div>
       <div>直流使用数量： {{kuaidian.shiyong}}</div>
       <div>使用率： {{kuaidian.shiyonglv}}</div>
     </div>
    </Panel>
  </div>
</template>
<script>
import request from "@/tools/request";
import Panel from "@/components/Panel";
import xingData from "@/mock/jsonData";
import KuaiData from "@/mock/kuaidian";
export default {
  name: "zhandian",
  components: {
    Panel,
  },
  data() {
    return {
      tableData: [],
      xingluochong: {},
      kuaidian: {}
     
    };
  },
  created() {
   this.getXing()
   this.getKuaiDian()
  },
  computed: {
    
    
  },
  methods: {

    unique(arr) {
        var set = new Set(arr);
      //方法1：
      return Array.from(set);
    },
    getXing(){
      let arr = xingData.data
       var directCount = 0 //直流总数
       var idleAmountDc = 0 //空闲直流数量
       var idleAmountAc = 0 //空闲交流
       var deviceAmountAc = 0 //总交流
       var hdFee =0 //电价
       var memberPrice = 0
       var memberCount = 0
       
      //  let data = this.unique(arr)
      for(var i=0;i<arr.length; i++){
         directCount+=arr[i]['directCount']
         idleAmountDc+=arr[i]['idleAmountDc']
         idleAmountAc+=arr[i]['idleAmountAc']
         deviceAmountAc+=arr[i]['deviceAmountAc']
         if(arr[i]['score']>2){
            hdFee+=arr[i]['hdFee']
            memberPrice+=arr[i]['memberPrice']
            memberCount++
         }
        

      }
      var zhiPercent = (idleAmountDc/directCount*100).toFixed(2) 
      var jiaoPercent = (idleAmountAc/deviceAmountAc*100).toFixed(2) 
      var siteCount = arr.length
      var elePrice = (hdFee/memberCount).toFixed(4)
      var Member = (memberPrice/memberCount).toFixed(4)
      this.xingluochong= { directCount ,  idleAmountDc,  idleAmountAc,  deviceAmountAc,  zhiPercent, jiaoPercent, siteCount, elePrice, Member, memberCount}
    },
    getKuaiDian() {
      let arr = KuaiData.data
       var directCount = 0 //直流总数
       var idleAmountDc = 0 //空闲直流数量
       var idleAmountAc = 0 //空闲交流
       var deviceAmountAc = 0 //总交流
       var guzhang = 0  //故障
       var liwang = 0 //离网
       var str = '特来电'
      for(var i=0;i<arr.length; i++){
        if(arr[i]['stationName'].indexOf("特来电") != -1){
          directCount+=arr[i]['directCount']
         idleAmountDc+=arr[i]['directLeftCount']
         idleAmountAc+=arr[i]['alternateLeftCount']
         deviceAmountAc+=arr[i]['alternateCount']
         liwang+=arr[i]['offLineCount']
         guzhang+=arr[i]['faultCount']
        }
         
      }
      var zhiPercent = (idleAmountDc/directCount*100).toFixed(2) 
      var jiaoPercent = (idleAmountAc/deviceAmountAc*100).toFixed(2) 
      var shiyong = (directCount - idleAmountDc-liwang - guzhang)
      var shiyonglv = ((directCount - idleAmountDc-liwang - guzhang)/directCount*100).toFixed(2) //s使用率
      var siteCount = arr.length
      this.kuaidian= { directCount ,  idleAmountDc,  idleAmountAc,  deviceAmountAc,  zhiPercent, jiaoPercent, siteCount, liwang, guzhang, shiyonglv,shiyong}
    }
  }
}
</script>
<style lang='scss' module>

</style>